home *** CD-ROM | disk | FTP | other *** search
- /****i* SOURCE_FILE/INFO
- *
- * NAME
- * ConfigFile.js
- *
- * USAGE
- * Part of Netobjects JavaScript Library.
- *
- * COPYRIGHT
- * Copyright ⌐ 2000-2005 Website Pros, Inc.
- * All Rights Reserved.
- *
- * This is an unpublished work protected by Website Pros, Inc.
- * as a trade secret, and is not to be used or disclosed except as
- * expressly provided in a written license agreement executed by
- * you and Website Pros, Inc.
- *
- * <copyright@websitepros.com>
- *
- * NOTES
- * JavaScript code.
- *
- *****/
- if (!IS.isModuleInitialized("IS.NOF.ConfigFile"))
- {
- /****h* NOF_JavaScript_Library/NOF.ConfigFile
- *
- * NAME
- * NOF.ConfigFile
- *
- * DESCRIPTION
- * encapsulates generic profile settings. Base class for all profiles.
- *
- * External dependencies: NOF.XML.XmlDocument, NOF.Contract, NOF.UTIL.ArrayList
- ****/
-
- /**
- * Constructor
- * @param name - optional, the name of the configFile (profile)
- */
- function NOF_ConfigFile( name ) {
- this.__proto__ = NOF_ConfigFile.prototype;
-
- if (arguments.length > 0){
- this.xmlDoc = NOF.XML.XmlDocument.create();
-
- this.configFileName = name;
- if (arguments.length > 1)
- this.configModuleType = arguments[1];
- }
- }
-
- function NOF_ConfigFile_ProtoBuilder() {
- var member = NOF_ConfigFile.prototype;
-
- member.fsiConfigFile = null;
- member.xmlDoc = null;
- member.XMLTemplate = null;
- member.configModuleType = null;
- member.fileExtension = ".xml";
-
- member.invalidChars = ["\\", "/", ":", "*", "?", "\"", "<", ">", "|"];
- //default name space. Must pe overwrite in subclasses.
- member.nameSpace = "xmlns:nof='http://www.netobjects.com/fusion/userProfile'";
-
- var method = NOF_ConfigFile.prototype;
-
- method.getConfigFilePath = getConfigFilePath;
- method.loadConfigFile = loadConfigFile;
- method.saveConfigFile = saveConfigFile;
- method.deleteConfigFile = deleteConfigFile;
-
- method.getConfigFiles = getConfigFiles;
- method.verifyDoc = verifyDoc;
-
- //dom handlers
- method.getNodeValue = getNodeValue;
- method.setNodeValue = setNodeValue;
- method.getElementsByTagName = getElementsByTagName;
- method.getChildNodes = getChildNodes;
- method.getChildNodesValues = getChildNodesValues;
- method.getNodeName = getNodeName;
- method.GetFSIProfileObj = GetFSIProfileObj;
- method.GetXMLDoc = GetXMLDoc;
-
-
- //
- /**
- **/
- method.encrypt = function (/*String*/ str) {
- return this.GetFSIProfileObj().Encrypt(str);
- }
-
- /**
- **/
- method.decrypt = function (/*String*/ str) {
- return this.GetFSIProfileObj().Decrypt(str);
- }
-
- /**
- * Verifies if there is already an XML document loaded. If not, a template
- * is loaded, to make possible the configFile saving.
- */
- function verifyDoc(){
- var doc = this.GetXMLDoc();
- if( doc.documentElement == null ){
- doc.loadXML( this.XMLTemplate );
- }
-
- NOF.Contract.Ensure(doc.documentElement != null, "Template parsing yield a null doc!");
- }
-
- function GetXMLDoc()
- {
- if (this.xmlDoc == null){
- this.xmlDoc = NOF.XML.XmlDocument.create();
- }
-
- return this.xmlDoc;
- }
-
- function GetFSIProfileObj()
- {
- //TODO : bellow lines should be wrapped by a if clause. Not all Fusion
- // version contains those dll's - problem occurs on /nof7 server app.
- if (this.fsiConfigFile == null){
- this.fsiConfigFile = new ActiveXObject(NOF.ProgId.FSIProfile);
- }
-
- return this.fsiConfigFile;
- }
- /**
- * Construct a list with the names of all the existing configFiles, for a
- * specified type
- * @param configModuleType - represents the configFile type: PhotoGallery,
- * E-commerce, OutputSettings
- * @return configFiles list
- */
- function getConfigFiles() {
-
- var configFiles = new Array();
- var profilePath = this.GetFSIProfileObj().GetProfilePath();
-
- var dirPath = profilePath +"/"+ this.configModuleType;
-
- var iter = new ActiveXObject(NOF.ProgId.FSIDirIterator);
- iter.DefineSearch(dirPath, '*'+this.fileExtension);
- var q;
- for (;;) {
- var p = iter.GetNext();
- if (!p.length)
- break;
- q = p.split('\\');
- p = q[q.length - 1];
- p = p.substring(0, p.lastIndexOf("."));
- configFiles[configFiles.length] = p;
- }
- //alert("getConfigFiles \n "+configFiles.join("\n") );
- return configFiles;
- }
-
- /**
- * @return the full configFile path
- */
- function getConfigFilePath(){
-
- return ( this.GetFSIProfileObj().GetProfilePath() + "/" + this.configModuleType + "/" + this.configFileName + this.fileExtension );
-
- }
-
- /**
- * load a specified configFile, via FSIConfigFile object
- * @param configFileName - the name of the configFile to be loaded,
- * if null, the name previously set for this configFile
- * is used.
- * @return true if succeeded, otherwise return false
- */
- function loadConfigFile( configFileName ) {
-
- if ( configFileName ) {
- this.configFileName = configFileName;
- }
-
- var configFileAsString = this.GetFSIProfileObj().LoadFile( this.configModuleType + "/" + this.configFileName + this.fileExtension );
-
-
- try {
-
- this.xmlDoc = NOF.XML.XmlDocument.create();
- this.xmlDoc.loadXML( configFileAsString );
-
- return true;
- }
- catch(e) {
- //alert(e);
- return false;
- }
- }
-
- /**
- * save the configFile coresponding to this object, based on its type, name
- * @param name - configFile name to be saved
- * @return true if succesfull
- */
- function saveConfigFile(name) {
-
- if(name){
- this.configFileName = name;
- }
-
- for ( var i = 0; i < this.invalidChars.length; i++ ) {
- if ( this.configFileName.indexOf(this.invalidChars[i]) > -1 ) {
- return false;
- }
- }
-
- return this.GetFSIProfileObj().SaveFile( this.configModuleType + "/" + this.configFileName + this.fileExtension, this.xmlDoc.xml );
- }
-
- /**
- * delete the configFile coresponding to this object, based on its type, name
- * @param name - the configFile name to be deleted
- * @return true if succesfull
- */
- function deleteConfigFile(name) {
- if(name){
- this.configFileName = name;
- }
- return this.GetFSIProfileObj().DeleteFile( this.configModuleType + "/" + this.configFileName + this.fileExtension );
- }
-
- method.setCDATANodeValue = function (/*string*/ nodeName, /*string*/ value) {
- //alert("setCDATANodeValue " + nodeName + " : " + value);
-
- if (value == null)
- return;
- this.verifyDoc();
-
- if ( typeof(nodeName) == "string") {
-
- this.xmlDoc.setProperty("SelectionNamespaces", this.nameSpace);
- var node = this.xmlDoc.documentElement.selectSingleNode(nodeName);
- var CDATASection = this.xmlDoc.createCDATASection(value);
- //var children = node.childNodes;
- node.replaceChild(CDATASection, node.childNodes.item(0));
- //node.appendChild(CDATASection);
-
- } else {
- nodeName.text = value;
- }
- }
-
- /**
- * set a node value
- * @param nodeName - node qualified name or node reference
- * @param value - new value
- */
- function setNodeValue(nodeName, value) {
- if (value == null)
- return;
- this.verifyDoc();
-
- if ( typeof(nodeName) == "string") {
- this.xmlDoc.setProperty("SelectionNamespaces", this.nameSpace);
- var node = this.xmlDoc.documentElement.selectSingleNode(nodeName);
- node.text = value;
- } else {
- nodeName.text = value;
- }
- }
-
- /**
- * get a node value
- * @param nodeName - node qualified name or node reference
- * @return node text
- */
- function getNodeValue(nodeName) {
- this.verifyDoc();
- this.xmlDoc.setProperty("SelectionNamespaces", this.nameSpace);
- if ( typeof(nodeName) == "string") {
- var node = this.xmlDoc.documentElement.selectSingleNode(nodeName);
- return node.text;
- } else
- return nodeName.text;
- }
-
- /**
- * get a node qualified name
- * @param node - node qualified name or node reference
- * @return node name
- */
- function getNodeName(node) {
- this.verifyDoc();
- this.xmlDoc.setProperty("SelectionNamespaces", this.nameSpace);
- if ( typeof(node) == "string") {
- var nodeRef = this.xmlDoc.documentElement.selectSingleNode(node);
- return nodeRef.nodeName;
- } else
- return node.nodeName;
- }
-
- /**
- * get a node list with the same qualified name
- * @param tagName - node qualified name
- * @return nodes list
- */
- function getElementsByTagName(tagName) {
- if (tagName == null || tagName == "")
- return null;
- this.verifyDoc();
- this.xmlDoc.setProperty("SelectionNamespaces", this.nameSpace);
- return this.xmlDoc.documentElement.getElementsByTagName(tagName);
- }
-
- /**
- * get a node childs
- * @param node - DOM node element
- * @return childs list
- */
- function getChildNodes(node) {
- if (node == null)
- return null;
- this.verifyDoc();
- this.xmlDoc.setProperty("SelectionNamespaces", this.nameSpace);
- if (typeof(node) == "string")
- node = this.xmlDoc.documentElement.selectSingleNode(node);
- return node.childNodes;
- }
-
- /**
- * get child nodes values from a specified node - parent
- * @param node - node qualified name - parent node
- * @return in Array with nodes values
- */
- function getChildNodesValues(node) {
- if (node == null)
- return null;
- this.verifyDoc();
- this.xmlDoc.setProperty("SelectionNamespaces", this.nameSpace);
- if (typeof(node) == "string")
- node = this.xmlDoc.documentElement.selectSingleNode(node);
- var childNodes = this.getChildNodes(node);
- var currentNode = childNodes.nextNode;
- var list = new NOF.UTIL.ArrayList();
- var i = 0;
- while (currentNode) {
- list.add(this.getNodeName(currentNode), this.getNodeValue(currentNode));
- i++;
- currentNode = childNodes.nextNode;
- }
- return list;
- }
-
- /**
- * @description get node attributes
- * @param node : node reference or qualified name
- */
- function getNodeAttributes(node) {
- this.verifyDoc();
- this.xmlDoc.setProperty("SelectionNamespaces", this.nameSpace);
- var nodeRef = null;
- if ( typeof(node) == "string")
- nodeRef = this.xmlDoc.documentElement.selectSingleNode(node);
- else
- nodeRef = node;
-
- return nodeRef.attributes;
- }
-
-
- return this;
- }
-
- NOF_ConfigFile_ProtoBuilder();
- NOF.__proto__.ConfigFile = NOF_ConfigFile;
-
- }